/**
 * 
 */
package com.alstudio.view.myrankinfo;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.loovee.imaohu.R;

/**
 * @author alonso lee
 * 
 */
public class MyRankInfoView extends LinearLayout {

	private boolean mClickable = true;
	private int mDrawable = -1;
	private String mTitle;
	private String mSubtitle;
	private int mColor = -1;
	private String itemCount;

	private LayoutInflater mLayoutInflater;

	/**
	 * @param context
	 */
	public MyRankInfoView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		initView(context);
	}

	private void initView(Context context) {
		mLayoutInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mLayoutInflater.inflate(R.layout.my_rank_info_item, this);
	}

	public int getDrawable() {
		return mDrawable;
	}

	public void setDrawable(int drawable) {
		this.mDrawable = drawable;
	}

	public String getTitle() {
		return mTitle;
	}

	public void setTitle(String title) {
		this.mTitle = title;
	}

	public String getSubtitle() {
		return mSubtitle;
	}

	public void setSubtitle(String summary) {
		this.mSubtitle = summary;
	}

	public int getColor() {
		return mColor;
	}

	public void setColor(int mColor) {
		this.mColor = mColor;
	}

	/**
	 * @param itemCount the itemCount to set
	 */
	public void setItemCount(String itemCount) {
		this.itemCount = itemCount;
	}
	
	/**
	 * @return the itemCount
	 */
	public String getItemCount() {
		return itemCount;
	}
	
	@Override
	public boolean isClickable() {
		return mClickable;
	}

	@Override
	public void setClickable(boolean clickable) {
		mClickable = clickable;
	}

	public void commit() {

		if (getDrawable() > -1) {
			((ImageView) findViewById(R.id.image))
					.setBackgroundResource(getDrawable());
		}
		if (getSubtitle() != null) {
			((TextView) findViewById(R.id.subtitle)).setText(getSubtitle());
		} else {
			((TextView) findViewById(R.id.subtitle)).setVisibility(View.GONE);
		}
		((TextView) findViewById(R.id.title)).setText(getTitle());
		if (getColor() > -1) {
			((TextView) findViewById(R.id.title)).setTextColor(getColor());
		}
		
		if(!TextUtils.isEmpty(getItemCount())){
			((TextView) findViewById(R.id.itemCount)).setText(getItemCount());
		}else{
			((TextView) findViewById(R.id.itemCount)).setVisibility(View.GONE);
		}
		
		if (isClickable()) {
//			setOnClickListener(new View.OnClickListener() {
//
//				@Override
//				public void onClick(View view) {
//					if (mClickListener != null)
//						mClickListener.onClick((Integer) getTag());
//				}
//
//			});
		} else {
			((ImageView) findViewById(R.id.chevron)).setVisibility(View.GONE);
		}

	}

}
